<?php

/**
 *  商品价格趋势
 */
namespace app\admin\model;
class SellerPriceRecords extends BaseModel
{
    protected $attributes = [
        'status' => [
            0 => '无效',
            1 => '有效'
        ],
        'seller_category' => [
            1 => '供应商',
            2 => '零售商'
        ],
        'price_category' => [
            1 => '售价',
            2 => '报价'
        ],
        'inventory_status' => [
            0=> '无货下架',
            1 => '有货在售',
            2 => '预售'
        ]
    ];

    protected $enumCallbacks = [
        'seller' => 'getSellerEnum',
        'supplier' => 'getSupplierEnum',   // 渠道商-供应商
        'retail' => 'getRetailEnum',  // 渠道商-零售商
        'model' => 'getModelEnum'
    ];

    /**
     *  渠道商-供应商
     */
    public function getSellerEnum()
    {
        return SellerInfo::where('is_del', 0)
            ->order('name ASC')
            ->column('id as value,name as label');
    }

    /**
     *  渠道商-供应商
     */
    public function getSupplierEnum()
    {
        return SellerInfo::where('is_del', 0)
            ->where('category','=', 1)
            ->order('name ASC')
            ->column('id as value,name as label');
    }


    /**
     *  渠道商-零售商
     */
    public function getRetailEnum()
    {
        return SellerInfo::where('is_del', 0)
            ->where('category','=', 2)
            ->order('name ASC')
            ->column('id as value,name as label');
    }


    /**
     *  获取机型枚举
     */
    public function getModelEnum()
    {
        return ModelInfo::order('model_name ASC')
            ->column('id as value,model_name as label');
    }

    /**
     *  渠道商名称
     */
    public function sellerName(){
        return $this->hasOne(SellerInfo::class, 'id', 'seller_id');
    }

    /**
     *  机型名称
     */
    public function modelName(){
        return $this->hasOne(ModelInfo::class, 'id', 'model_id');
    }

    /**
     *  获取字段枚举
     */
    public function getFieldEnum($field)
    {
        return $this->getEnum($field,[],'label');
    }

    /**
     *  获取字段枚举
     */
    public function getFieldValue($field)
    {
        return $this->attributes[$field];
    }

}
